package org.knot.autojmx.example;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.knot.autojmx.annotations.AutoJMX;
import org.knot.autojmx.api.AutoJMXAPI;
import org.knot.autojmx.exception.AutoJMXException;

@AutoJMX
public class InitMBean {
	
	public static List<Object> mbeans = new ArrayList<Object>();
	
	static {
		try {
			
			TestJMXBeanAPI1 testjmx1 = AutoJMXAPI.Instance().createJMXBean(TestJMXBeanAPI1.class, new Class[]{int.class}, new Object[]{3}, "testJMXBeanAPI1", null);
			TestJMXBeanAPI2 testjmx2 = AutoJMXAPI.Instance().createJMXBean(TestJMXBeanAPI2.class);
			InitMBean testjmx3 = AutoJMXAPI.Instance().createJMXBean(InitMBean.class);
			mbeans.add(testjmx1);
			mbeans.add(testjmx2);
			mbeans.add(testjmx3);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public void detoryMbean(String name) throws InstantiationException, IllegalAccessException, AutoJMXException
	{
		AutoJMXAPI.Instance().destoryJMXBean(name);
	}

	
	public void createMbean(String name) throws InstantiationException, IllegalAccessException, AutoJMXException, ClassNotFoundException, SecurityException, IllegalArgumentException, NoSuchMethodException, InvocationTargetException
	{
		Class clazz = this.getClass().getClassLoader().loadClass(name);
		Object o = AutoJMXAPI.Instance().createJMXBean(clazz);
	}
}
